import java.util.Arrays;

/**
 * Created with IntelliJ IDEA.
 * Description:冒泡排序
 * User:龙宝
 * Date:2023-11-12
 * Time:15:37
 */
public class BubbleSort {
    public static void main(String[] args) {
        int[] arr = {9,4,1,2,0,6,5,3,10,7,8};
        bubbleSort(arr);
        System.out.println(Arrays.toString(arr));
    }

    private static void bubbleSort(int[] arr) {
        for(int i = 0;i<arr.length;i++) {
            int flg = 0;
            for(int j = i+1;j<arr.length;j++) {
                if(arr[i] > arr[j]) {
                    int tmp = arr[i];
                    arr[i] = arr[j];
                    arr[j] = tmp;
                    flg = 1;
                }
            }
            if(flg == 0) {
                break;
            }
        }
    }
}
